﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class chaxun_jigou : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["sTittle"] = "机构查询";
            if (Session["sRole"].ToString() == "管理员")
            {
                Conn zconn = new Conn();
                string zsql = "SELECT DISTINCT jigou FROM account WHERE ((role = '机构') OR (role = '管理员'))";
                SqlDataReader reader1 = zconn.Reader(zsql);
                while (reader1.Read())
                {
                    string zjigou = reader1.GetString(0);//取得计数的机构名称
                    //zsql = "select count(username),sum(yiskf) from account where role='学员' and jigou='" + zjigou + "'";
                    zsql = "select count(username) from account where jigou='" + zjigou + "'";
                    string zcount = zconn.sqlTwo(zsql);
                    if (zcount != "0")
                    {
                        //zsql = "update account set zhuceRS=" + zcount.Substring(0, zcount.IndexOf("|")) + ",yiskf=" + zcount.Substring(zcount.IndexOf("|") + 1) + " where (((role = '机构') OR (role = '管理员')) AND (jigou='" + zjigou + "'))";
                        zsql = "update account set zhuceRS=" + zcount + " where (((role = '机构') OR (role = '管理员')) AND (jigou='" + zjigou + "'))";
                        int noth = zconn.ExeSql(zsql);
                    }
                }
                zconn.Dispose();
            }
            else
            {
                this.DropDownList1.Enabled = false;
                DetailsView1.Fields[3].Visible = false;
                DetailsView1.Fields[4].Visible = false;
            }
        }
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue.ToString() == "远程教育平台")
        {
            SqlDataSource1.SelectCommand = "SELECT [jigou], [id], [role], [username1], [city], [email], [mobile], [grjj],[zhuceRS],[yiskf] FROM [account] WHERE [role]='管理员'";
        }
        else 
        {
            SqlDataSource1.SelectCommand = "SELECT [jigou], [id], [role], [username1], [city], [email], [mobile], [grjj],[zhuceRS],[yiskf] FROM [account] WHERE ([role]='机构' AND [jigou]='" + DropDownList1.SelectedValue.ToString() + "')";
        }
    }
}
